<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        input{
            display: block;
            text-align: center;
            width: 300px;
            margin: auto;
        }
        div{
            width: 300px;
            height: 300px;
            margin: 50px auto;
            background-color: green;
        }

        button{
            display: block;
            margin: auto;
        }

    </style>
</head>
<body>
    
    <input type="text" id="text" value="https://www.baidu.com">
    <div id="qrcode"></div>
    <button id="sc">生成</button>

    <script src="./jquery.min.js"></script>
    <script src="./qrcode.js"></script>

    <script>

        // 步骤
        // 1.引入js库
        // 2.生成二维码

        const qrcode = new QRCode(document.getElementById("qrcode"),{
            width:300,
            height:300
        }) ;

        function makeCode(){
            const elText = document.getElementById("text") ;

            if(!elText.value) {
                alert("请输入内容") ;
                elText.value = "https://www.baidu.com"
                elText.focus() ;
            }
            qrcode.makeCode(elText.value) ;
        }

        makeCode() ;


        const make = document.getElementById("sc").onclick = () => makeCode() ;

    </script>

</body>
</html>